﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public static partial class contest
    {
        public static dynamic addOrEditContest(int cid, string title, DateTime start_time,
            DateTime over_time, bool disabled, string description, bool is_public)
        {
            var sql = new Sql.SqlDataContext();
            var result = sql.Contest.Where(row => row.cid == cid);
            if (result != null)
                sql.Contest.DeleteAllOnSubmit(result);
            Sql.Contest con = new Sql.Contest();
            con.cid = cid;
            con.title = title;
            con.startTime = start_time;
            con.overTime = over_time;
            con.disabled = disabled;
            con.description = description;
            con.is_public = is_public;
            sql.Contest.InsertOnSubmit(con);
            sql.SubmitChanges();
            return new
            {
                success = true
            };
        }
    }
}
